<template>
  <div>
    <a-modal :visible="visbileSetting" :title="indicatorSettingModalParam.indicatorName" 
      :width="400"
      wrapClassName="calcParam"
      :closable="false"
      :cancelButtonProps="{style:{display:'none'}}"
      @ok="closeIndicatorSetting">
      <div style="padding: 2em;">
        <div v-for="(item, i) in indicatorConfigs" :key="item.paramNameKey">
          <div style="margin-bottom: 16px;display: flex; align-items: center;">
              <span style="margin-right: 24px;">{{ item.paramNameKey }}</span>
              <a-input v-model:value="indicatorSettingModalParam.calcParams[i]" :min="item.min"></a-input>
          </div>
        </div>
      </div>
    </a-modal>
  </div>
</template>
<script lang="ts">
import { Modal } from 'ant-design-vue';
export default {
  components: {
    AModal: Modal
  },
};
</script>
<script lang="ts" setup>
  import { ref,onMounted } from 'vue';
  import {getConfig} from './indicator'
  const visbileSetting = ref(true);
  const indicatorSettingModalParam = ref({
    calcParams:[]
  });
  const emit = defineEmits(['closeIndicatorSetting'])

  function showIndicatorSetting() {
    visbileSetting.value = true;
  }
  function closeIndicatorSetting() {
    emit('closeIndicatorSetting', indicatorSettingModalParam.value.indicatorName,
    indicatorSettingModalParam.value.calcParams,
    indicatorSettingModalParam.value.paneId); 
  }

  const indicatorConfigs = ref([]);
  
  defineExpose({ showIndicatorSetting });

  const props = defineProps({
    "indicatorSettingModalParams": {
      type: Object
    }
  });

  onMounted(()=> {
    indicatorSettingModalParam.value = props.indicatorSettingModalParams[0];
    let indicatorName = indicatorSettingModalParam.value.indicatorName;
    var configs = getConfig(indicatorName);
    for(var i=0; i<indicatorSettingModalParam.value.calcParams.length;i++) {
      var param = indicatorSettingModalParam.value.calcParams[i];
      if(!param && configs[i].default) {
        indicatorSettingModalParam.value.calcParams[i] = configs[i].default
      }
    }
    indicatorConfigs.value = configs;
  });
</script>
<style scoped>

</style>